const Router = require('koa-router');
const router = new Router();
const readFilePromise = require('fs-readfile-promise');


router.get('/getUserDetailByID/:id', async (ctx, next) => {
    let results = await readFilePromise("./public/data/" + "users.json", 'utf8')
    //console.log(results)
    //转成 JSON 数组
    let data = JSON.parse(results);
    // 在数组中查找 userXXX
    let user = data["user" + ctx.params.id]

    if (typeof (user) == 'undefined') {
        ctx.body = {
            status: 'success',
            message: "没有找到 ID 为" + ctx.params.id + " 的用户！"
        }
    }
    else {
        ctx.body = {
            status: 'success',
            message: JSON.stringify(user)
        }
    }

}
)

module.exports = router;